$(document).ready(function(){
	var videoUrl;
	//CARACTERISTICAS( VIDEO, MUST HAVE, LOOK DA SEMANA
	if( $("#caracteristicas .value-field").length>0 ){
		
		$("#caracteristicas .value-field").each(function(){
			if( $(this).text().toLowerCase() == "must have" ){
				$("#daslu-mania").css("display","block");
				createSeal("img_mustHave.png","#daslu-mania .seal");
			}
			
			if( $(this).text().toLowerCase() == "look da semana" ){
				$("#daslu-mania").css("display","block");
				createSeal("img_lookSemana.png","#daslu-mania .seal");
			}
			
			if( /^http:\/\//.test( $(this).text().toLowerCase() ) ){
				videoUrl = $(this).text();
				setTimeout(createEmbedVideoThumb,1,"/Control/ArquivoExibir.aspx?NomeArquivo=video-thumb.jpg","ul.thumbs",videoUrl);
			}
		});
	}
	
	//PRODUCT IMAGE ZOOM
	$("#show #include #image .image-zoom #image-main").mouseover(function(){
		setTimeout(superZoom_init,100);
	});
	
	/*GIFT LIST */
	var giftListUrl = $("#product .apresentacao #show .thumbs li a img").eq(0).attr("src");
	$(".giftList-wrapper .giftList-content .image").attr("src",giftListUrl);
	
	$(".giftList-wrapper .giftlistinsertsku .giftlistinsertsku-lists li:not(.wishlist-title)").css("display","none");
	
	setTimeout(wishlist_init,1);
	
	$(".giftList-wrapper .giftlistinsertsku ul").prepend( $("<li></li>").attr("class","wishlist-title").append( $("<a></a>").text("Selecione") ) );		
	
	$("#product .about .especifications .wishlish a").click(function(){
		$(".giftList-wrapper").fadeIn("slow");
	});
	
	//fechar
	$(".giftList-wrapper .giftList-content a.wishlist-fechar").click(function(){
		$(".giftList-wrapper").fadeOut("slow");
	});	
	
	//remover a palavra POR do preco da wishlist
	$(".giftList-wrapper span.price em.valor-por").text( $(".giftList-wrapper span.price em.valor-por").text().replace(/Por\s+/gi,"") );
});





function createEmbedVideo(videoUrl, destination){
	if( $("#embed-wrapper").length==0 ){
		var object = 
			"<div id='embed-wrapper'>"+
				"<object width='469' height='469'>"+
					"<param name='movie' value='"+videoUrl+"'></param>"+
					"<param name='allowFullScreen' value='true'></param>"+
					"<param name='allowscriptaccess' value='always'></param>"+
					"<param name='wmode' value='transparent'></param>"+
					"<embed src='"+videoUrl+"' wmode='transparent' type='application/x-shockwave-flash' width='469' height='469' allowscriptaccess='always' allowfullscreen='true'></embed>"+
				"</object>"+
			"</div>";
		$(destination).append( $(object) );
	}
}

function createEmbedVideoThumb(imgSrc, ulDes, url){
	$(ulDes).prepend(
			$("<li></li>").append( $("<a></a>").attr({"id":"embed-video","href":"javascript:void(0)"}).append( $("<img />").attr("src",imgSrc) ) )
	);
	
	//EVENTOS
	$("#product .apresentacao #show .thumbs li a").bind("click", function() {
		$("#embed-wrapper").remove();
		if( $(this).attr("id") == "embed-video" ){
			createEmbedVideo( url, "#include #image");
			$("#embed-wrapper").show();
		}
	});
}

function createSeal(sealImg,target) {
	var img = "<img class='seal-img' width='76' height='76' src='/Control/ArquivoExibir.aspx?NomeArquivo="+sealImg+"' />";
	$(target).append( $(img) );
}

function superZoom_init(){
    if( $(window).width()<=1024 ){
        $(".jqZoomWindow").delay(100).css("left","507px");
    }else{
        $(".jqZoomWindow").css("left","678px");
    }
}

function wishlist_init(){
	$(".giftList-wrapper .giftlistinsertsku .giftlistinsertsku-lists li.wishlist-title").click(function(){
		$(this).parent().find("li:not(.wishlist-title)").slideToggle("slow");
	});
}